//
//  NameViewController.m
//  QT
//
//  Created by 甘世清 on 2025/1/3.
//

#import "NameViewController.h"

@interface NameViewController ()<UITextFieldDelegate>
 
@property (nonatomic , strong) SQCustomButton * nvBtn;
@property (nonatomic , strong) SQCustomButton * nanBtn;
@end

@implementation NameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    self.zx_hideBaseNavBar = YES;
}
- (void)SQ_UIViewForSelfView{
    UILabel * label1  = [[UILabel alloc]init];
    label1.text = SQNSLocalString(@"头像");
    label1.font = FONT_MEDIUM(14);
    label1.textColor = SQColor999999;
    [self.view addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(16);
        make.top.equalTo(self.view).offset(30);
    }];
    [self.view addSubview:self.headerBtn];
    [self.headerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(100);
        make.top.equalTo(label1.mas_bottom).offset(10);
    }];
    
    UILabel * label12  = [[UILabel alloc]init];
    label12.text = SQNSLocalString(@"昵称");
    label12.font = FONT_MEDIUM(14);
    label12.textColor = SQColor999999;
    [self.view addSubview:label12];
    [label12 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(16);
        make.top.equalTo(self.headerBtn.mas_bottom).offset(20);
    }];
    UIView * nameBG = [[UIView alloc]init];
    nameBG.layer.cornerRadius = 24;
    nameBG.layer.masksToBounds = YES;
    nameBG.layer.borderWidth = 0.5;
    nameBG.layer.borderColor = SQHexColor(@"#000000", 0.2).CGColor;
    [self.view addSubview:nameBG];
    [nameBG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SCREEN_WIDETH-100);
            make.height.mas_equalTo(48);
            make.centerX.equalTo(self.view);
            make.top.equalTo(label12.mas_bottom).offset(10);
    }];
    [self.view addSubview:self.nameTextField];
    [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SCREEN_WIDETH-100);
            make.height.mas_equalTo(48);
            make.centerX.equalTo(self.view);
            make.top.equalTo(label12.mas_bottom).offset(15);
    }];
    
    UILabel * label123  = [[UILabel alloc]init];
    label123.text = SQNSLocalString(@"性别");
    label123.font = FONT_MEDIUM(14);
    label123.textColor = SQColor999999;
    [self.view addSubview:label123];
    [label123 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(16);
        make.top.equalTo(self.nameTextField.mas_bottom).offset(20);
    }];
    [self.view addSubview:self.nanBtn];
    [self.view addSubview:self.nvBtn];
    [self.nanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(110);
        make.top.equalTo(label123.mas_bottom).offset(0);
        make.centerX.equalTo(self.view).offset(-70);
    }];
    [self.nvBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(110);
        make.top.equalTo(label123.mas_bottom).offset(0);
        make.centerX.equalTo(self.view).offset(70);
    }];
    [self.view addSubview:self.reloadBtn];
    [self.reloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.height.mas_equalTo(50);
            make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight-20);
    }];
    WS(weakSelf);
    [self.reloadBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_ClickButtonClick];
    }];
    [self.headerBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
            [weakSelf SQ_HeaderViewqButtonClick];
    }];
    
    [self.nanBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf.view endEditing:YES];
        weakSelf.page = 1;
        weakSelf.nanBtn.image = SQGetImage(@"男生 亮");
        weakSelf.nvBtn.image = SQGetImage(@"女生 灰");
        weakSelf.nanBtn.textColor = SQColor333333;
        weakSelf.nvBtn.textColor = SQColor666666;
    }];
    [self.nvBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        weakSelf.page = 2;
        [weakSelf.view endEditing:YES];
        weakSelf.nvBtn.image = SQGetImage(@"女生 亮");
        weakSelf.nanBtn.image = SQGetImage(@"男生 灰");
        weakSelf.nanBtn.textColor = SQColor666666;
        weakSelf.nvBtn.textColor = SQColor333333;
    }];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
-(void)SQ_ClickButtonClick{
    
    
    if (self.btntouchBlock) {
        self.btntouchBlock();
    }  
}

-(void)SQ_HeaderViewqButtonClick{
    WS(weakSelf);
    [self.view endEditing:YES];
    ImagePopView * vc = [[ImagePopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 200+FootHeight)];
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:nil
                                             popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleBottom;
    [pop pop];
    LSTPopViewWK(pop)
    [pop setBgClickBlock:^{
        [wk_pop dismiss];
    }];
    [vc setAddImageArrayBlock:^(NSArray<UIImage *> * _Nonnull imageArray) {
        weakSelf.headerBtn.SQBackimageView.image = imageArray.firstObject;
        weakSelf.headerBtn.imageView.hidden = YES;
        [wk_pop dismiss];
    }];
}

- (SQCustomButton *)headerBtn{
    if (!_headerBtn) {
        _headerBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(100, 100) midmargin:0];
        _headerBtn.image = SQGetImage(@"header");
        _headerBtn.SQBackimageView.contentMode = UIViewContentModeScaleAspectFill;
        _headerBtn.clipsToBounds = YES;
        _headerBtn.layer.cornerRadius = 50;
        _headerBtn.layer.borderColor = SQColor333333.CGColor;
        _headerBtn.layer.borderWidth = 2;
        _headerBtn.backgroundColor = UIColor.whiteColor;
    }
    return _headerBtn;
}
- (SQCustomButton *)reloadBtn{
    if (!_reloadBtn) {
        _reloadBtn = [[SQCustomButton alloc]initType:SQCustomButtonLeftImageType imageSize:CGSizeMake(0, 0) midmargin:10];
        _reloadBtn.text = SQNSLocalString(@"下一个");
        _reloadBtn.image = SQGetImage(@"xiayige");
        _reloadBtn.font = FONT_MEDIUM(14);
        _reloadBtn.textColor = UIColor.whiteColor;
        _reloadBtn.layer.cornerRadius = 10;
        _reloadBtn.layer.borderColor = SQColor333333.CGColor;
        _reloadBtn.layer.borderWidth = 0.5;
        _reloadBtn.backgroundColor = SQColorDA70D6;
    }
    return _reloadBtn;
}
- (FSTextView *)nameTextField{
    if (!_nameTextField) {
        _nameTextField = [[FSTextView alloc]init];
        _nameTextField.textAlignment = NSTextAlignmentCenter;
        _nameTextField.font = FONT_MEDIUM(16);
        _nameTextField.textColor = SQColor(@"#000000");
        _nameTextField.backgroundColor = UIColor.clearColor;
        _nameTextField.returnKeyType = UIReturnKeyDone;
        _nameTextField.maxLength = 15;
    }
    return _nameTextField;
}
- (SQCustomButton *)nvBtn{
    if (!_nvBtn) {
        _nvBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(100, 100) midmargin:0];
        _nvBtn.image = SQGetImage(@"女生 灰");
        _nvBtn.text = SQNSLocalString(@"女");
        _nvBtn.textColor = SQColor666666;
        _nvBtn.font = FONT_MEDIUM(12);
    }
    return _nvBtn;
}
- (SQCustomButton *)nanBtn{
    if (!_nanBtn) {
        _nanBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(100, 100) midmargin:0];
        _nanBtn.image = SQGetImage(@"男生 亮");
        _nanBtn.text = SQNSLocalString(@"男");
        _nanBtn.textColor = SQColor333333;
        _nanBtn.font = FONT_MEDIUM(12);
    }
    return _nanBtn;
}
@end
